using System;
using System.Windows.Forms;

namespace Ditty.CSharp.ResharperKeygen
{
    public partial class KeyGenUI : Form
    {
        public KeyGenUI()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string userName = textBox1.Text.Trim();
            var companyName = textBox2.Text.Trim();
            if (userName != string.Empty)
            {
                textBox2.Text = new KeyGen5 { UserName = userName, CompanyName = companyName, Version = getVersion(comboBox1.SelectedIndex) }.GetLicense();
                if(textBox2.Text != null && textBox2.Text.Length > 0)
                {
                    Clipboard.SetText(textBox2.Text??String.Empty);
                    MessageBox.Show(this, "Copied to Clipboard.");
                }
            }
        }
        private static int getVersion(int index)
        {
            var version = 0;
            switch (index)
            {
                case 0:
                    version = 5000;
                    break;
                case 1:
                    version = 6000;
                    break;
            }
            return version;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void textBox2_Enter(object sender, EventArgs e)
        {
            textBox2.SelectionStart = 0;
            textBox2.SelectionLength = textBox2.Text.Length;
        }

        private void textBox2_Click(object sender, EventArgs e)
        {
            textBox2_Enter(sender, e);
        }
    }
}
